import {
    ChangePassword,
    UserInfo,
    UserModel
} from '@/api/system/user/UserModel'
import { reactive } from 'vue'

export default function useInfoBaseModel() {
    // 表单绑定的数据
    const addModel = reactive<UserInfo>({
        id: '',
        avatar: '',
        username: '',
        nickname: '',
        mobile: '',
        email: '',
        role_name: '',
        created_at: '',
        permissions: []
    })

    const changePasswordModel = reactive<ChangePassword>({
        old_password: '',
        password: '',
        confirm_password: ''
    })

    //表单验证规则
    const rules = reactive({
        nickname: [
            {
                required: true,
                message: '请填写昵称',
                trigger: 'change'
            }
        ],
        mobile: [
            {
                required: true,
                message: '请填写手机号码',
                trigger: 'change'
            }
        ],
        email: [
            {
                required: true,
                message: '请填写邮箱',
                trigger: 'change'
            }
        ]
    })

    const passwordRules = reactive({
        old_password: [
            {
                required: true,
                message: '请填写旧密码',
                trigger: 'change'
            }
        ],
        password: [
            {
                required: true,
                message: '请填写新密码',
                trigger: 'change'
            }
        ],
        confirm_password: [
            {
                required: true,
                message: '请填写确认密码',
                trigger: 'change'
            }
        ]
    })

    return {
        addModel,
        rules,
        changePasswordModel,
        passwordRules
    }
}
